<script type="text/javascript">
$(function(){
	var pg = App.soagov.faceImplPicker.ui, pp = pg.params || {}
		, bd = pg.children('.body'), hd = bd.children('.head')
		, ft = bd.children('.bottom'), slo = {};

	var frm = {
		key: hd.seek('keys'),
		find: hd.seek('find'),
		ok: ft.seek('ok'),
		close: ft.seek('close')
	};
	
	var gd = pg.find('.grid').mac('grid', {
		key: 'id',
		cols : [{
			field: 'id', width: 24,
			title: pp.multi?'<input type="checkbox" name="all" />':'',
			render: function(r) {
				var a = $('<input type="' + (pp.multi? 'checkbox':'radio')
					+ '" name="keys" value="' + r.id + '"/>');
				a.change(function(){
					var k = a.attr('value');
					if (a.is(':checked')) {
						slo[k] = gd.data[k];
					} else {
						delete slo[k];
					}
				});
				return a;
			}
		}, {
			field: 'impl',title: '已知实现类', width: 536
		}, {
			field: 'ver', title : '版本', width: 120
		},{
			field: 'opt', title : '操作', width: 60,
			render: function(r, tr, gd) {
				return $('<span class="a"></span>').click(function(){
					mac.confirm('确定要 删除 实现类 ' + r.impl + ' 吗？', function(){
						$.post(App.soagov.ctx + '/face/impl/delete.do', {
							id: r.id
						}, function(rs){
							var ro = mac.eval(rs);
							if (ro.success) {
								gd.load();
							} else {
								mac.alert(ro.data, ro.params);
							}
						});
					});
					return false;
				}).append('删除');
			}
		}],
		loader: {
			url: App.soagov.ctx + '/face/impl/list.do',
			params: { pageNo: 1, pageSize: 7, faceId: pp.faceId },
			autoLoad: true
		},
		pagerLength: 10,
		afterLoad: function(dd, po, me){
			me.find('.tr').each(function(i, tr){
				$(tr).dblclick(function(){
					frm.ok.click();
				});
			});
			if (pp.multi) {
				me.seek('all').removeAttr('checked');
				me.seek('keys').each(function(i, n){
					var a = $(n), k = a.attr('value');
					if (slo[k]) {
						a.attr('checked', 'checked');
					} else {
						a.removeAttr('checked');
					}
				});
			}
		}
	});
	function adjust(){
		var h = pg.height();
		gd.parent().height(h - hd.height() - ft.height() - 16);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
	
	frm.find.click(function(e) {
		gd.load({ faceId: pp.faceId, key: frm.key.val() });
	});
	frm.key.keydown(frm.find.click);
	frm.ok.click(function(){
		if (pp.multi) {
			$.each(gd.selected || [], function(i, a){
				var k = $(a).attr('name');
				slo[k] = gd.data[k];
			});
			pp.callback(slo);
		} else {
			var sl = gd.selected || [];
			if (sl.length) {
				var k = $(sl[0]).attr('name');
				pg.callback(gd.data[k]);
			}
		}
		pg.close();
	});
	frm.close.click(function(){
		pg.close();
	});
});
</script>
<div class="head">
	关键字：<input type="text" name="key" />
	<button name="find">查找</button>
</div>
<div id="main">
	<div class="grid"></div>
</div>
<div class="bottom">
	<button name="ok">确定</button>
	<button name="close">关闭</button>
</div>